-[NSCFData writeStreamHandleEvent:]: unrecognized selector sent to instance in a stream callback

Posted by user295491 on Stack Overflow See other posts from Stack Overflow or by user295491
Published on 2010-03-17T09:08:24Z Indexed on 2010/03/17 9:11 UTC
Read the original article Hit count: 378

Hi everyone,

I am working with streams and sockets in iPhone SDK 3.1.3 the issue is when the program accept a callback and I want to handle this writestream callback the following error is triggered " Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSCFData writeStreamHandleEvent:]: unrecognized selector sent to instance 0x17bc70'" But I don't know how to solve it because everything seems fine. Even when I run the debugger there is no error the program works. Any hint here will help!

The code of the callback is:

void myWriteStreamCallBack (CFWriteStreamRef stream, CFStreamEventType eventType, void *info){  

   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   Connection *handlerEv = [(Connection *)info retain] autorelease];
   [handlerEv writeStreamHandleEvent:eventType];
   [pool release];  
}

The code of the writeStreamHandleEvent:

- (void)writeStreamHandleEvent:(CFStreamEventType) eventType{
    switch(eventType) {
        case kCFStreamEventOpenCompleted:
            writeStreamOpen = YES;
            break;

        case kCFStreamEventCanAcceptBytes:
            NSLog(@"Writing in the stream");
            [self writeOutgoingBufferToStream];
            break;

        case kCFStreamEventErrorOccurred:
            error = CFWriteStreamGetError(writeStream);
            fprintf(stderr, "CFReadStreamGetError returned (%ld, %ld)\n", error.domain, error.error);
            CFWriteStreamUnscheduleFromRunLoop(writeStream, CFRunLoopGetCurrent(),kCFRunLoopCommonModes);
            CFWriteStreamClose(writeStream);
            CFRelease(writeStream);
            break;

        case kCFStreamEventEndEncountered:
            CFWriteStreamUnscheduleFromRunLoop(writeStream, CFRunLoopGetCurrent(),kCFRunLoopCommonModes);
            CFWriteStreamClose(writeStream);
            CFRelease(writeStream);
            break;
    }

}

The code of the stream configuration:

CFSocketContext ctx = {0, self, nil, nil, nil};

CFWriteStreamSetClient (writeStream,registeredEvents,                               (CFWriteStreamClientCallBack)&myWriteStreamCallBack,(CFStreamClientContext *)(&ctx) );

CFWriteStreamScheduleWithRunLoop (writeStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

You can see that there is nothing strange!, well at least I don't see it.

Thank you in advance.

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.1.3

Related posts about streams